<template>
  <div class="index-wrap">
    <div v-if="showPage == 1">
      <div class="index-box" @click="toPath1('/workmanage')">
        <img src="./c_01.png" class="pic1" onclick="return false"/>
        <span class="title">招聘管理</span>
        <img src="./in.png" class="pic-in" onclick="return false"/>
      </div>
      <div class="index-box" @click="toPath('/employmanage')">
        <img src="./c_02.png" class="pic1" onclick="return false"/>
        <span class="title">员工管理</span>
        <img src="./in.png" class="pic-in" onclick="return false"/>
      </div>
      <div class="index-box" @click="toPath('/affiliationmanage')">
        <img src="./c_03.png" class="pic1" onclick="return false"/>
        <span class="title">员工归属管理</span>
        <img src="./in.png" class="pic-in" onclick="return false"/>
      </div>
      <!--<div class="index-box" @click="toPath('/inviteRewards')">-->
        <!--<img src="./c_09.png" class="pic1" onclick="return false"/>-->
        <!--<span class="title">邀请奖励审核</span>-->
        <!--<img src="./in.png" class="pic-in" onclick="return false"/>-->
      <!--</div>-->
      <div class="index-box" @click="toPath2('/leaveindex')">
        <img src="./c_06.png" class="pic1" onclick="return false"/>
        <span class="title">离职工资管理</span>
        <img src="./in.png" class="pic-in" onclick="return false"/>
      </div>
      <div class="index-box" @click="toPath('/lendmanage')">
        <img src="./c_04.png" class="pic1" onclick="return false"/>
        <span class="title">借支审核</span>
        <img src="./in.png" class="pic-in" onclick="return false"/>
      </div>
      <div class="index-box" @click="toPath('/daymoney')">
        <img src="./c_05.png" class="pic1" onclick="return false"/>
        <span class="title">日日薪管理</span>
        <img src="./in.png" class="pic-in" onclick="return false"/>
      </div>
      <div class="index-box" @click="toPath('/dayreportlist')">
        <img src="./c_08.png" class="pic1" onclick="return false"/>
        <span class="title">日输送报表</span>
        <img src="./in.png" class="pic-in" onclick="return false"/>
      </div>

      <div class="index-box" @click="toPath('/message')">
        <img src="./c_07.png" class="pic1" onclick="return false"/>
        <span class="title">消息中心</span>
        <span class="msg-num" v-show="infoNum">{{infoNum}}</span>
        <img src="./in.png" class="pic-in-msg" onclick="return false"/>
      </div>
    </div>

    <!--微信绑定手机号-->
    <v-phone v-model="showModal" @bindPhone="bindCustomerPhone"></v-phone>

    <empty v-if="showPage == 2"></empty>
  </div>
</template>

<script>
  import {baseUrl} from "../../config/env"
  import phone from "../../components/phone"
  import empty from "../../components/errorpage"
  import {getUrlKey, setSessionStore, getSessionStore, removeSessionStore} from "../../config/util"

  export default {
    data() {
      return {
        showPage: 0,
        showModal: false,
        userSign: "",
        countentPhone: "",
        infoNum: 0
      }
    },
    mounted() {
      //获取微信
      this.userSign = getUrlKey("success"); //微信openid
      this.countentPhone = getUrlKey("countentPhone"); //手机框 0弹出1不弹出
      let base64 = require('js-base64').Base64;
      if (this.userSign != "" && this.userSign != "null" && this.userSign != null) {
        setSessionStore("success", base64.encode(this.userSign));
        this.userSign = base64.decode(getSessionStore("success"));
      } else {
        this.userSign = base64.decode(getSessionStore("success"));
      }

      if (this.countentPhone == "0") {
        this.showModal = true;
      } else {
        this.queryResidentAuth();
      }
    },
    methods: {
      queryResidentAuth() {//是否驻厂权限
        let time = (new Date()).getTime();
        let url = baseUrl + "/resident/get_resident_role?timestamp=" + time;
        let param = {"sgin": this.userSign, "timestamp": time};
        let signature = this.$signature(url, param);

        this.axios.get(baseUrl + "/resident/get_resident_role?sgin=" + this.userSign + "&type=" + "&auth=" + signature + "&timestamp=" + time).then((res) => {
          let resultObj = res.data;
          if (resultObj.code == 0 && resultObj.data == 1) {
            this.showPage = 1;
            this.queryMsgNum();
          } else {
            this.showPage = 2;
          }
        }).catch(() => {
          this.$vux.toast.text("网络异常", "middle");
        });
      },
      bindCustomerPhone(phone) {//绑定微信客户手机号
        this.$vux.loading.show({
          text: '加载中',
        });

        let time = (new Date()).getTime();
        let url = baseUrl + "/wx_user/set_phone?timestamp=" + time;
        let param = {"sgin": this.userSign, "timestamp": time};
        let signature = this.$signature(url, param);

        //绑定微信手机
        this.axios.get(baseUrl + "/wx_user/set_phone?sgin=" + this.userSign + "&phone=" + phone + "&userName=" + "&userUrl=" + "&auth=" + signature + "&timestamp=" + time).then((res) => {
          let resultObj = res.data;
          this.$vux.loading.hide();
          if (resultObj.code == 0 && resultObj.data == 1) {
            this.queryResidentAuth();
          } else {
            this.showModal = true;
            this.$vux.toast.text(resultObj.msg, "middle");
          }
        }).catch(() => {
          this.$vux.loading.hide();
          this.$vux.toast.text("网络异常", "middle");
        });
      },
      queryMsgNum() {//查询消息未读数
        this.axios.get(baseUrl + "/info/query_unreadNum?sgin=" + this.userSign + "&type=1").then((res) => {
          let resultObj = res.data;
          if (resultObj.code == 0 && resultObj.data != null) {
            this.infoNum = resultObj.data > 99 ? 99 : resultObj.data;
          } else {
            this.$vux.toast.text(resultObj.msg);
          }
        });
      },
      toPath(page) {
        this.$router.push(page);
      },
      toPath1(page) {
        sessionStorage.removeItem("work");
        this.$router.push(page);
      },
      toPath2(page){
        removeSessionStore("withholdList");
        removeSessionStore("subsidyList");
        removeSessionStore("leave");
        removeSessionStore("leaveEndTime");
        removeSessionStore("subsidy_withhold");
        this.$router.push(page);
      }
    },
    components: {
      "v-phone": phone,
      empty
    }
  }
</script>

<style lang="stylus" scoped>
  @import "../../assets/stylus/mixin.styl"

  .index-wrap
    wh(100%, 100%)
    background: rgba(242, 242, 242, 1)
    overflow: hidden
    .index-box
      fj(space-between, center)
      wh(100%, 1.28rem)
      background: rgba(255, 255, 255, 1)
      border-bottom: 0.027rem solid rgba(242, 242, 242, 1)
      &:nth-child(3)
        margin-bottom: 0.267rem
      &:nth-child(7)
        margin-bottom: 0.267rem
      &:last-child
        justify-content: flex-start
      .pic1
        margin-left: 0.24rem
        wh(0.8rem, 0.8rem)
      .title
        margin-left: 0.24rem
        size-color(0.427rem, rgba(51, 51, 51, 1))
      .pic-in
        wh(0.32rem, 0.32rem)
        margin-left: auto
        margin-right: 0.32rem
      .pic-in-msg
        margin-left: auto
        wh(0.32rem, 0.32rem)
        margin-right: 0.32rem
      .msg-num
        position: absolute
        right: 1.067rem
        wh(0.427rem, 0.427rem)
        background: rgba(255, 83, 83, 1)
        border-radius: 50%
        font-size: 0.293rem;
        font-weight: 500
        color: rgba(255, 255, 255, 1)
        fj(center, center)
</style>
